package com.atguigu.educms.service.impl;

import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.mapper.CrmBannerMapper;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author qing
 * @since 2021-08-18
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {
    /**
     * redis中的@Cacheable注解用于查询方法上，将查询的结果存入到缓存中.
     * @return
     */

    @Cacheable(value = "banner",key = "'selectIndexList'")
    @Override
    public List<CrmBanner> selectAllBanner() {
        //根据id进行降序排列，显示排列之后前两条记录
        QueryWrapper<CrmBanner> crmBannerQW = new QueryWrapper<>();
        crmBannerQW.orderByDesc("id");
        //last方法,拼接sql语句
        crmBannerQW.last("limit " +
                "2");
        List<CrmBanner> crmBanners = baseMapper.selectList(crmBannerQW);
        return crmBanners;
    }
}
